#include "timerdialog.h"
#include <QVBoxLayout>
#include <QMessageBox>

TimerDialog::TimerDialog(QWidget *parent) :
    QDialog(parent)
{
    m_label=new QLabel("timer :0", this);
    m_setButton = new QPushButton("set", this);
    m_stopButton = new QPushButton("stop", this);
    m_timerValue = new QLineEdit("300", this);

    setLayout(new QVBoxLayout);

    layout()->addWidget(m_label);
    layout()->addWidget(m_timerValue);
    layout()->addWidget(m_setButton);
    layout()->addWidget(m_stopButton);

    connect(m_setButton, SIGNAL(clicked()), this, SLOT(setTimer()));
    connect(m_stopButton, SIGNAL(clicked()), this, SLOT(stopTimer()));

    m_timerId1 =0;
}

void TimerDialog::setTimer()
{
    killTimer(m_timerId1);
    m_timerId1 = startTimer(m_timerValue->text().toInt());
}

void TimerDialog::stopTimer()
{
    killTimer(m_timerId1);
}
void TimerDialog::timerEvent(QTimerEvent *)
{
    static int counter=0;
    m_label->setText(QString("timer : ") + QString::number(++counter));
}

/*void TimerDialog::setTimer()
{
    QMessageBox::information(this, "info", "set timer");
}
void TimerDialog::stopTimer()
{
    QMessageBox::information(this, "info", "stop timer");
}*/
